# 设置文件夹 A 和 B 的路径
$folderA = "D:\BaiduNetdiskDownload\haitao_images_gz"
$folderB = "D:\BaiduNetdiskDownload\haitao_images_gz_flat"

# 检查文件夹 B 是否存在，如果不存在则创建
if (-not (Test-Path -Path $folderB)) {
    New-Item -ItemType Directory -Path $folderB | Out-Null
}

# 获取文件夹 A 中的所有一级文件夹
$folders = Get-ChildItem -Path $folderA -Directory

foreach ($folder in $folders) {
    $folderName = $folder.Name
    
    # 获取当前文件夹中的所有文件
    $files = Get-ChildItem -Path $folder.FullName

    foreach ($file in $files) {
        $newFileName = $folderName + '+' + $file.Name
        
        # 重命名文件并移动到文件夹 B
        # Write-Host $file.FullName "=>" (Join-Path $folderB $newFileName)
        Move-Item -Path $file.FullName -Destination (Join-Path $folderB $newFileName)
    }
}
